package com.nashuju.web.util;

import java.util.ArrayList;
import java.util.List;

import com.nashuju.web.entity.sys.SysClass;

public class ClassTreeUtil {
    public static List<SysClass> buildTreeData(List<SysClass> list) {

        List<SysClass> menu = new ArrayList<SysClass>();

        resolveClassTree(list, 0, menu);

        return menu;
    }

    public static int resolveClassTree(List<SysClass> menus, int parentMenuId, List<SysClass> nodes) {

        int count = 0;
        for (SysClass menu : menus) {
            if (menu.getParentId() == parentMenuId) {
                SysClass node = new SysClass();

                nodes.add(node);
                node.setScId(menu.getScId());
                node.setClassName(menu.getText());
                node.setUrl(menu.getUrl());
                node.setUrltarget(menu.getUrltarget());
                node.setIsshow(menu.getIsshow());
                node.setPos(menu.getPos());
                node.setParentId(menu.getParentId());
                node.setDescription(menu.getDescription());
                node.setChildren(new ArrayList<SysClass>());

                resolveClassTree(menus, menu.getId(), node.getChildren());
                count++;
            }
        }
        return count;
    }
}
